<?php
/************************************/
// Application controller
// thaodx@gmail.com
/************************************/

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Application extends CI_Controller {
	public function index(){
		$this->load->model('Application_model', 'appModel');
		$this->load->model('Category_model', 'cateModel');
		if(isset($_POST['cmd'])){
			if($_POST['cmd'] == 'reorder' && is_array($_POST['category_order'])){
				if($this->appModel->reorderCategory($_POST['category_order'])){
					$data['msg'] = 'Update category order successful.';
				}
			}
			elseif($_POST['cmd'] == 'delete' && is_array($_POST['item'])){
				if($this->appModel->deleteCategory($_POST['item'])){
					$data['msg'] = 'Delete category successful.';
				}
			}
		}
		$params = array(
			'offset' => 0,
			'limit' => LIMIT_APP_PAGE
			);

		$data['app'] = $this->appModel->getListApplication($params);
		$this->layout->title('Application / List / ');
		$cate = $this->cateModel->getAllCategory();
		$data['cateOpt'] = $this->cateModel->buildOptCatRecursive(array_reverse($cate));

		$this->layout->view('application_index', $data);// Render view and layout
	}
}